; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.0
; Language:       English
; Platform:       Win9x / NT
; Author:         A.N.Other <myemail@nowhere.com>
;
; Script Function:
;	Template AutoIt script.
;
; ----------------------------------------------------------------------------


; ----------------------------------------------------------------------------
; Set up our defaults
; ----------------------------------------------------------------------------

;AutoItSetOption("MustDeclareVars", 1)
;AutoItSetOption("MouseCoordMode", 0)
;AutoItSetOption("PixelCoordMode", 0)
;AutoItSetOption("RunErrorsFatal", 0)
;AutoItSetOption("TrayIconDebug", 1)
;AutoItSetOption("WinTitleMatchMode", 4)


; ----------------------------------------------------------------------------
; Script Start
; ----------------------------------------------------------------------------

If $CmdLine[0] == 1 AND $CmdLine[1] == "cfgfile" Then
	;$hostnamefile = FileOpen("c:\windows\system32\z\hostname", 0)
	; Check if file opened for reading OK
	;If $hostnamefile = -1 Then
    	;	MsgBox(0, "Error", "Unable to open file c:\windows\system32\z\hostname.")
    	;	Exit
	;EndIf
	;$computername = FileReadLine($hostnamefile)
	;FileClose($hostnamefile)
	
	$ipfile = FileOpen("c:\windows\system32\z\network", 0)
	; Check if file opened for reading OK
	If $ipfile = -1 Then
    		MsgBox(0, "Error", "Unable to open file c:\windows\system32\z\network.")
    		Exit
	EndIf
	$computername 	= FileReadLine($ipfile,1)
	$ipaddress 	= FileReadLine($ipfile,2)
	$netmask  	= FileReadLine($ipfile,3)
	$gateway   	= FileReadLine($ipfile,4)
	$dns	   	= FileReadLine($ipfile,5)
	FileClose($ipfile)

ElseIf $CmdLine[0] <> 5 Then
	MsgBox(4096, "Network-setup Usage", "Usage: Network-setup  ComputerName ipaddress netmask gateway dns1,dns2", 5)
		Exit (0)

Else
	$computername 	= $CmdLine[1]
	$ipaddress	= $CmdLine[2]
	$netmask	= $CmdLine[3]
	$gateway	= $CmdLine[4]
	$dns		= $CmdLine[5]
EndIf
 

 ;MsgBox(4096, "computername", $computername)
 ;MsgBox(4096, "ipaddress", $ipaddress)	
 ;MsgBox(4096, "netmask", $netmask)
 ;MsgBox(4096, "gateway", $gateway)
 
 $file = FileOpen("d:\tools\spilot_set\winnt.cfg", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open winnt.cfg.")
    Exit
EndIf

$line = FileReadLine($file,5)
$array1 = StringSplit ( $line, "{" )
;MsgBox(4096, "test", $array1[2])
$array2 = StringSplit ( $array1[2],"]")
;MsgBox(4096, "test", $array2[1])
$NicNumber = "{"&$array2[1]
;MsgBox(4096, "test", $NicNumber)
FileClose($file)

$Nic1 = "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Tcpip\Parameters\Interfaces\"&$NicNumber
RegWrite($Nic1, "IPAddress", "REG_MULTI_SZ", $ipaddress)
RegWrite($Nic1, "SubnetMask", "REG_MULTI_SZ", $netmask)
RegWrite($Nic1, "DefaultGateway", "REG_MULTI_SZ", $gateway)
RegWrite($Nic1, "NameServer", "REG_SZ", $dns)

$Nic2 = "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\"&$NicNumber&"\Parameters\Tcpip"
RegWrite($Nic2, "IPAddress", "REG_MULTI_SZ", $ipaddress)
RegWrite($Nic2, "SubnetMask", "REG_MULTI_SZ", $netmask)
RegWrite($Nic2, "DefaultGateway", "REG_MULTI_SZ", $gateway)

RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\ComputerName\ComputerName", "ComputerName", "REG_SZ", $computername)

RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\ComputerName\ActiveComputerName", "ComputerName", "REG_SZ", $computername)

RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Tcpip\Parameters", "NV Hostname", "REG_SZ", $computername)
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Tcpip\Parameters", "Hostname", "REG_SZ", $computername)

$Nic3 = "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet002\Services\Tcpip\Parameters\Interfaces\"&$NicNumber
RegWrite($Nic3, "IPAddress", "REG_MULTI_SZ", $ipaddress)
RegWrite($Nic3, "SubnetMask", "REG_MULTI_SZ", $netmask)
RegWrite($Nic3, "DefaultGateway", "REG_MULTI_SZ", $gateway)
RegWrite($Nic3, "NameServer", "REG_SZ", $dns)


$Nic4 = "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet002\Services\"&$NicNumber&"\Parameters\Tcpip"
RegWrite($Nic4, "IPAddress", "REG_MULTI_SZ", $ipaddress)
RegWrite($Nic4, "SubnetMask", "REG_MULTI_SZ", $netmask)
RegWrite($Nic4, "DefaultGateway", "REG_MULTI_SZ", $gateway)


RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet002\Control\ComputerName\ComputerName", "ComputerName", "REG_SZ", $computername)


RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet002\Services\Tcpip\Parameters", "NV Hostname", "REG_SZ", $computername)
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet002\Services\Tcpip\Parameters", "Hostname", "REG_SZ", $computername)






